// Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
//
// Licensed under the Mulan PSL v2.
// You can use this file according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of the License at
//
//     http://license.coscl.org.cn/MulanPSL2
//
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
// FOR MORE DETAILS.

/**
 * @brief
 *
 * @version  0.1
 * @author   yuanchenxi
 * @date     2024.12.20
 */
#include "Import/BDFImport/BulkData/Material/MAT9FParser.h"

#include "gtest/gtest.h"

#include "DataStructure/Common/Constant.h"

#include "DBManager/DBServiceFactory.h"
#include "DBManager/IService/Input/Material/IMAT9FService.h"

#include "Import/BDFImport/BDFParserBase.h"
using namespace SG::DBManager;
using namespace SG::Import;

using SG::DataStructure::Common::TOLERANCE;
extern std::shared_ptr<DBServiceFactory> DB_SERVICEFACTORY;
extern std::vector<std::string>          dividedEntryInfo;

class MAT9FParserTest : public ::testing::Test
{
  public:
    static void SetUpTestSuite ()
    {
        DB_SERVICEFACTORY->ClearDatabase ();
    }
};

TEST_F (MAT9FParserTest, ParseEntry1)
{
    std::vector<std::string> Entry = { "MAT9F    459     300.                                            200.",
                                       "                                         550.",
                                       "                                 110.            220.    2.283-9" };
    BDF::divideBulkEntry (Entry, dividedEntryInfo);
    SG::Import::BDF::BULKDATA::ParseMAT9F (DB_SERVICEFACTORY, dividedEntryInfo);
    SG::DataStructure::FEM::MAT9FData data;

    ASSERT_TRUE (DB_SERVICEFACTORY->get<IMAT9FService> ()->FindById (459, data) == SG::DataStructure::Common::Status::STATUS_Success);

    ASSERT_TRUE (data.m_id == 459);

    ASSERT_TRUE (data.m_GE == 0);

    ASSERT_TRUE (data.m_G[0] == 300.0);
    ASSERT_TRUE (data.m_G[1] == 0);
    ASSERT_TRUE (data.m_G[2] == 0);
    ASSERT_TRUE (data.m_G[3] == 0);
    ASSERT_TRUE (data.m_G[4] == 0);
    ASSERT_TRUE (data.m_G[5] == 0);
    ASSERT_TRUE (data.m_G[6] == 200.0);
    ASSERT_TRUE (data.m_G[7] == 0);
    ASSERT_TRUE (data.m_G[8] == 0);
    ASSERT_TRUE (data.m_G[9] == 0);
    ASSERT_TRUE (data.m_G[10] == 0);
    ASSERT_TRUE (data.m_G[11] == 550.0);
    ASSERT_TRUE (data.m_G[12] == 0);
    ASSERT_TRUE (data.m_G[13] == 0);
    ASSERT_TRUE (data.m_G[14] == 0);
    ASSERT_TRUE (data.m_G[15] == 0);
    ASSERT_TRUE (data.m_G[16] == 0);
    ASSERT_TRUE (data.m_G[17] == 0);
    ASSERT_TRUE (data.m_G[18] == 110.0);
    ASSERT_TRUE (data.m_G[19] == 0);
    ASSERT_TRUE (data.m_G[20] == 220.0);

    ASSERT_TRUE (data.m_GEIJ[0] == 0);
    ASSERT_TRUE (data.m_GEIJ[1] == 0);
    ASSERT_TRUE (data.m_GEIJ[2] == 0);
    ASSERT_TRUE (data.m_GEIJ[3] == 0);
    ASSERT_TRUE (data.m_GEIJ[4] == 0);
    ASSERT_TRUE (data.m_GEIJ[5] == 0);
    ASSERT_TRUE (data.m_GEIJ[6] == 0);
    ASSERT_TRUE (data.m_GEIJ[7] == 0);
    ASSERT_TRUE (data.m_GEIJ[8] == 0);
    ASSERT_TRUE (data.m_GEIJ[9] == 0);
    ASSERT_TRUE (data.m_GEIJ[10] == 0);
    ASSERT_TRUE (data.m_GEIJ[11] == 0);
    ASSERT_TRUE (data.m_GEIJ[12] == 0);
    ASSERT_TRUE (data.m_GEIJ[13] == 0);
    ASSERT_TRUE (data.m_GEIJ[14] == 0);
    ASSERT_TRUE (data.m_GEIJ[15] == 0);
    ASSERT_TRUE (data.m_GEIJ[16] == 0);
    ASSERT_TRUE (data.m_GEIJ[17] == 0);
    ASSERT_TRUE (data.m_GEIJ[18] == 0);
    ASSERT_TRUE (data.m_GEIJ[19] == 0);
    ASSERT_TRUE (data.m_GEIJ[20] == 0);
}
